package com.hrp.hrpdao;

import com.hrp.domain.TransportRecord;
import com.hrp.domain.UimmsPrice;
import com.hrp.domain.UimmsReceiveMoney;
import com.sun.corba.se.impl.ior.OldJIDLObjectKeyTemplate;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.StatementType;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2019/5/6 0006.
 */
@Mapper
public interface PriceSettingDao {


    @Insert("   insert into UIMMS_PRICE([startTime],[endTime],[varietiesId],[varietiesName],[supplierIdStr],[supplierStrName],[receiverIdStr],[receiverStrName],[price],[updateTime],[insertTime],[czry],[memo])values(#{startTime},#{endTime},#{varietiesId},#{varietiesName},#{supplierIdStr},#{supplierStrName},#{receiverIdStr},#{receiverStrName},#{price},getdate(),getdate(),#{czry},#{memo}) ")
    @Options(useGeneratedKeys=true,keyProperty="id")
    void savePriceSetting(UimmsPrice uimmsPrice);


    @Select("select * from UIMMS_PRICE where id = #{id}")
    UimmsPrice getPriceSettingById(Integer id);


    @Update(" update UIMMS_PRICE set [startTime]=#{startTime},[endTime]=#{endTime},[varietiesId]=#{varietiesId},[varietiesName]=#{varietiesName},[supplierIdStr]=#{supplierIdStr},[supplierStrName]=#{supplierStrName},[receiverIdStr]=#{receiverIdStr},[receiverStrName]=#{receiverStrName},[price]=#{price},[updateTime]=getdate(),[czry]=#{czry},[memo]=#{memo} where id=#{id} ")
    void updatePriceSetting(UimmsPrice uimmsPrice);

    @Select("<script>"
            + " select * from ( select *,ROW_NUMBER() over(order by id desc) row from UIMMS_PRICE ) T where row in "
            + "<foreach item='item' index='index' collection='strList' open='(' separator=',' close=')'>"
            + "#{item}"
            + "</foreach>"
            + "</script>")
    List<UimmsPrice> getPriceSettingByPage(@Param("strList") List<Integer> strList);


    @Select("select count(*) total from UIMMS_PRICE")
    Integer getTotalCount();

    @Options(statementType= StatementType.CALLABLE)
    @Select({ "exec usp_uimms_batchUpdatePrice #{id}" })
    List<Map<String,Object>> batchUpdatePrice(@Param("id") Integer id);

    @Select("select * from UIMMS_PRICE where varietiesId=#{varietiesId} and charindex (#{supplierId},supplierIdStr)>0  and charindex (#{receiverId},receiverIdStr)>0 and #{sendTime}>=startTime and #{sendTime}<=endTime")
    List<UimmsPrice> getPriceSettingByInfo(@Param("varietiesId") Integer varietiesId,@Param("supplierId") String supplierId,@Param("receiverId") String receiverId,@Param("sendTime") String sendTime);
}
